<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <title>代码生成器</title>
  <script src="../../static/kaige/js/szload.js"></script>
  <style>
    .curdtag {
      min-width: 150px;
      height: 28px;
      line-height: 28px;
      padding: 3px 5px 3px 6px;
      margin-bottom: 10px;
      overflow: auto;
    }
  </style>
</head>

<body>
  <div class="kaige-body kaige-btn-radius">
    <table class="layui-table" id="pageTable" lay-filter="pageTable" lay-size="sm"></table>
  </div>

  <script>
    load_init_js(function () {
      layui.config({
        base: szoapcpath + '/static/kaige/layuiextend/'
      }).use(['kaige'], function () {
        var element = layui.element,
          layer = layui.layer,
          table = layui.table,
          form = layui.form,
          kaige = layui.kaige,
          $ = layui.$;

        kaige.table({
          elem: '#pageTable',
          url: "/makecode/curd",
          id: 'pageTable',
          page: false,
          height:'full-30',
          cols: [[
            { type: 'numbers', title: '序号' }
            , { field: 'Name', title: '表名', sort: true, width: 300 }
            , { field: 'Comment', title: '备注', width: 300 }
            , { field: 'is_make', sort: true, title: '是否生成', width: 120, templet: function (d) { return yesno2tag(d.is_make) } }
            , { field: 'maketype', sort: true, title: '手/自', width: 100, templet: function (d) { return out2tag(d.maketype, '自动', '手动') } }
            , { field: 'ctime', title: '生成时间', width: 170 }
            , { title: '操作', toolbar: '#dtrbar', align: 'center', width: 100, fixed: 'right' }
          ]],
          done: function(res, curr, count){
            
          }
        });

        //列表-监听单元格行工具事件dtrbar
        table.on('tool(pageTable)', function (obj) {
          var that = this;
          var data = obj.data;
          switch (obj.event) {
            case 'edit':
              baredit(data);
              break;
            case 'view':
              barview(data);
              break;
          }
        });

        //查看
        function barview(d) {

        }

        //编辑
        function baredit(d) {
          if (d.is_make == 1) {
            layer.msg('已经存在的功能，不能再生成！');
            return false;
          }
          kaige.form({
            url: "/makecode/edit",
            data: { id: d.id },
            id: 'kaige',
            area: ['700px', '500px'],
            title: '<i class="layui-icon layui-icon-edit"></i> 代码生成器',
            tablelayid: 'pageTable',
            overflow: false,
            encode: 1,
            callbefore: function (layero, index) {
              form.on('select(tableName)', function (data) {
                var tablename = data.value;
                var md = tablename.split('_');
                var shtml = '<div class="curdtag">数据模型(app\\common\\model\\' + md[1] + '\\' + md[1].slice(0, 1).toUpperCase() + md[1].slice(1) + md[2].slice(0, 1).toUpperCase() + md[2].slice(1) + '.php)</div>';
                shtml += '<div class="curdtag">数据访问层(app\\common\\dao\\' + md[1] + '\\' + md[2].slice(0, 1).toUpperCase() + md[2].slice(1) + 'Dao.php)</div>';
                shtml += '<div class="curdtag">服务业务层(app\\common\\service\\' + md[1] + '\\' + md[2].slice(0, 1).toUpperCase() + md[2].slice(1) + 'Service.php)</div>';
                shtml += '<div class="curdtag">控制器(app\\backend\\controller\\' + md[1] + '\\' + md[2].slice(0, 1).toUpperCase() + md[2].slice(1) + '.php)</div>';
                shtml += '<div class="curdtag">前端视图(\\pc\\pages\\' + md[1] + '\\' + md[2] + '\\index.html)</div>';
                $('#make_result').html(shtml);
              });
            }
          });
        }


      });
    });
  </script>
  <script type="text/html" id="dtrbar">
    <div class="layui-btn-group">
      {{# if(d.is_make != 1){ }}
      <button class="layui-btn layui-btn-sm" lay-event="edit" title="打开生成器"><i class="layui-icon layui-icon-edit"></i></button>
      {{# } }}
    </div>
  </script>
  <script type="text/html" id="kaige_form_html">
    <form class="layui-form layui-form-pane kaige-body-form" style="padding: 5px;" lay-filter="kaige_form_lay_filter">
      {{# if(d.id){ }}
      <input type="hidden" name="id" value="{{ d.id }}" />
      {{# } }}
      <div class="layui-form-item">
        <label class="layui-form-label">数据表</label>
        <div class="layui-input-block">
          <select name="tableName" lay-filter="tableName" id="tableName" required lay-verify="required">
            <option value="">选择未实现功能的数据表</option>
            {{#  layui.each(d.dbTables, function(index, item){ }}
            <option value="{{ item.Name }}">{{ item.Name + ' [' + item.Comment +']' }}</option>
            {{#  }) }}
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">即将生成</label>
        <div class="layui-input-block" id="make_result">
          <div class="curdtag">数据模型(model)</div>
          <div class="curdtag">数据访问层(dao)</div>
          <div class="curdtag">服务业务层(service)</div>
          <div class="curdtag">控制器(controller)</div>
          <div class="curdtag">前端视图(pages)</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">操作人</label>
        <div class="layui-input-block">
          {{# if (d.id){ }}
          <input name="handle_name" value="{{ d.handle_name || '' }}"  required lay-verify="required" class="layui-input layui-disabled" type="text" readonly>
          {{# }else{ }}
          <input name="handle_name" value="{{ d.einfo.real_name || '' }}"  required lay-verify="required" class="layui-input layui-disabled" type="text" readonly>
          {{# } }}
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">版权</label>
        <div class="layui-input-block">
          <input name="copyright" value="©2022 泉州市盛筑信息科技有限公司 版权所有"  required lay-verify="required" class="layui-input" type="text">
        </div>
      </div>
      <div class="layui-form-item layui-hide">
        <button class="layui-hide" lay-submit="" id="kaige_form_btn_save" lay-filter="kaige_form_btn_save">保存数据</button>
      </div>
    </form>
  </script>

</body>

</html>